Imports Phoenix.DataAccess
Imports Phoenix.Security
Imports Phoenix.Forms.Login

Namespace Forms.View
    Public Class LoginView
        Inherits Phoenix.Forms.Login.XPLoginScreen

#Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call

        End Sub

        'UserControl overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            '
            'LoginView
            '
            Me.DockPadding.Bottom = 48
            Me.DockPadding.Top = 48
            Me.DrawVerticalSplitLine = True
            Me.Name = "LoginView"
            Me.Size = New System.Drawing.Size(869, 635)

        End Sub

#End Region

        Private mFilter As String

        Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            HeaderText = Res.ApplicationTitle

            'Loading user list
            Dim dv As DataView = New DataView(AppDataLayer.Employees)

            If AppConfig.UserModeEnabled Then
                mFilter = "(Sys=False) and (IsOperator=True)"
            Else
                mFilter = "(IsOperator=True) or (Sys=True)"
            End If

            dv.RowFilter = mFilter

            LoadUserList(dv)
        End Sub

        Protected Overrides Function TryLogin(ByVal UserTag As Object, ByVal Password As String)
            Dim user As DataSetData.Employee = CType(UserTag, DataSetData.Employee)

            If Not user.IsPasswordNull Then
                If user.Password <> Password Then Return False
            End If
            AppLogin(user)
            Return True
        End Function

        Friend Sub SafeMode()
            Dim dv As DataView = New DataView(AppDataLayer.Employees)
            dv.RowFilter = mFilter & " or (EmployeeID=1)"

            LoadUserList(dv)
        End Sub

        Private Sub LoadUserList(ByVal dv As DataView)
            'UserList.SuspendLayout()
            UserList.Controls.Clear()
            For Each view As DataRowView In dv
                Dim user As DataSetData.Employee = view.Row
                Dim needpass As Boolean = True
                If user.Password = String.Empty Then
                    needpass = False
                End If

                Dim box As XPLoginEntry = AddLogin(user.FullName, GetSecurityRoleTitle(user.SecurityLevel), needpass, user)
                box.Icon = Helpers.EmployeeHelper.GetEmployeeImage(user)
            Next
            'UserList.SuspendLayout()
            PerformLayout()
        End Sub
    End Class


End Namespace